package org.xiaojinlong.playground;

import java.io.File;

public class Hello {

    public static void main(String[] args) {
//        int[] a = {1, 2, 3, 4, 5};
//        StdRandom.shuffle(a);
//        System.out1.println(Arrays.toString(a));
//        System.out.println(isPrime(3387));
        Internal root = new Internal();
        root.left = new Leaf(8);
        root.right = new Leaf(3);
        System.out.println(treeSum(root));
    }

    public static boolean isPrime(int N) {
        if (N < 2) {
            return false;
        } else {
            for (int i = 2; i * i <= N; i++) {
                if (N % i == 0) {
                    return false;
                }
            }
            return true;
        }
    }

    private static class Node {
    }

    private static class Leaf extends Node {
        int value;
        Leaf(int value) {
            this.value = value;
        }
    }

    private static class Internal extends Node {
        Node left, right;
    }

    static int treeSum(Node tree) {
        if (tree instanceof Leaf) {
            return ((Leaf) tree).value;
        } else {
            return treeSum(((Internal) tree).left) + treeSum(((Internal) tree).right);
        }
//        System.out.println("jingjing" + new File("foo"));
    }


}

